home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / The World of Computer Software.iso / srcuc.zip / PROSTTY.C < prev    next >
C/C++ Source or Header  |  1992-05-05  |  6KB  |  166 lines

  1. /* -*-C-*-
  2.  
  3. $Header: /scheme/src/microcode/RCS/prostty.c,v 1.4 1992/05/05 06:37:58 jinx Exp $
  4.  
  5. Copyright (c) 1987-1992 Massachusetts Institute of Technology
  6.  
  7. This material was developed by the Scheme project at the Massachusetts
  8. Institute of Technology, Department of Electrical Engineering and
  9. Computer Science.  Permission to copy this software, to redistribute
  10. it, and to use it for any purpose is granted, subject to the following
  11. restrictions and understandings.
  12.  
  13. 1. Any copy made of this software must include this copyright notice
  14. in full.
  15.  
  16. 2. Users of this software agree to make their best efforts (a) to
  17. return to the MIT Scheme project any improvements or extensions that
  18. they make, so that these may be included in future releases; and (b)
  19. to inform MIT of noteworthy uses of this software.
  20.  
  21. 3. All materials developed as a consequence of the use of this
  22. software shall duly acknowledge such use, in accordance with the usual
  23. standards of acknowledging credit in academic research.
  24.  
  25. 4. MIT has made no warrantee or representation that the operation of
  26. this software will be error-free, and MIT is under no obligation to
  27. provide any services, by way of maintenance, update, or otherwise.
  28.  
  29. 5. In conjunction with products arising from the use of this material,
  30. there shall be no use of the name of the Massachusetts Institute of
  31. Technology nor of any adaptation thereof in any advertising,
  32. promotional, or sales literature without prior written consent from
  33. MIT in each case. */
  34.  
  35. /* Primitives to perform I/O to and from the console. */
  36.  
  37. #include "scheme.h"
  38. #include "prims.h"
  39. #include "ostty.h"
  40. #include "osctty.h"
  41. #include "osfile.h"
  42. #include "osio.h"
  43.  
  44. DEFINE_PRIMITIVE ("TTY-INPUT-CHANNEL", Prim_tty_input_channel, 0, 0,
  45.   "Return the standard input channel.")
  46. {
  47.   PRIMITIVE_HEADER (0);
  48.   PRIMITIVE_RETURN (long_to_integer (OS_tty_input_channel ()));
  49. }
  50.  
  51. DEFINE_PRIMITIVE ("TTY-OUTPUT-CHANNEL", Prim_tty_output_channel, 0, 0,
  52.   "Return the standard output channel.")
  53. {
  54.   PRIMITIVE_HEADER (0);
  55.   PRIMITIVE_RETURN (long_to_integer (OS_tty_output_channel ()));
  56. }
  57.  
  58. DEFINE_PRIMITIVE ("TTY-X-SIZE", Prim_tty_x_size, 0, 0,
  59.   "Return the display width in character columns.")
  60. {
  61.   PRIMITIVE_HEADER (0);
  62.   PRIMITIVE_RETURN (long_to_integer (OS_tty_x_size ()));
  63. }
  64.  
  65. DEFINE_PRIMITIVE ("TTY-Y-SIZE", Prim_tty_y_size, 0, 0,
  66.   "Return the display height in character lines.")
  67. {
  68.   PRIMITIVE_HEADER (0);
  69.   PRIMITIVE_RETURN (long_to_integer (OS_tty_y_size ()));
  70. }
  71.  
  72. DEFINE_PRIMITIVE ("TTY-COMMAND-BEEP", Prim_tty_command_beep, 0, 0,
  73.   "Return a string that, when written to the display, will make it beep.")
  74. {
  75.   PRIMITIVE_HEADER (0);
  76.   PRIMITIVE_RETURN
  77.     (char_pointer_to_string ((unsigned char *) (OS_tty_command_beep ())));
  78. }
  79.  
  80. DEFINE_PRIMITIVE ("TTY-COMMAND-CLEAR", Prim_tty_command_clear, 0, 0,
  81.   "Return a string that, when written to the display, will clear it.")
  82. {
  83.   PRIMITIVE_HEADER (0);
  84.   PRIMITIVE_RETURN
  85.     (char_pointer_to_string ((unsigned char *) (OS_tty_command_clear ())));
  86. }
  87.  
  88. DEFINE_PRIMITIVE ("TTY-NEXT-INTERRUPT-CHAR", Prim_tty_next_interrupt_char, 0, 0,
  89.   "Return the next interrupt character in the console input buffer.\n\
  90. The character is returned as an unsigned integer.")
  91. {
  92.   PRIMITIVE_HEADER (0);
  93.   PRIMITIVE_RETURN (long_to_integer (OS_tty_next_interrupt_char ()));
  94. }
  95.  
  96. DEFINE_PRIMITIVE ("TTY-GET-INTERRUPT-ENABLES", Prim_tty_get_interrupt_enables, 0, 0,
  97.   "Return the current keyboard interrupt enables.")
  98. {
  99.   PRIMITIVE_HEADER (0);
  100.   {
  101.     Tinterrupt_enables mask;
  102.     OS_ctty_get_interrupt_enables (&mask);
  103.     PRIMITIVE_RETURN (long_to_integer (mask));
  104.   }
  105. }
  106.  
  107. DEFINE_PRIMITIVE ("TTY-SET-INTERRUPT-ENABLES", Prim_tty_set_interrupt_enables, 1, 1,
  108.   "Change the keyboard interrupt enables to MASK.")
  109. {
  110.   PRIMITIVE_HEADER (1);
  111.   {
  112.     Tinterrupt_enables mask = (arg_integer (1));
  113.     OS_ctty_set_interrupt_enables (&mask);
  114.   }
  115.   PRIMITIVE_RETURN (UNSPECIFIC);
  116. }
  117.  
  118. DEFINE_PRIMITIVE ("TTY-GET-INTERRUPT-CHARS", Prim_tty_get_interrupt_chars, 0, 0,
  119.   "Return the current interrupt characters as a string.")
  120. {
  121.   PRIMITIVE_HEADER (0);
  122.   {
  123.     unsigned int i;
  124.     unsigned int num_chars = (OS_ctty_num_int_chars ());
  125.     SCHEME_OBJECT result = (allocate_string (num_chars * 2));
  126.     cc_t * int_chars = (OS_ctty_get_int_chars ());
  127.     cc_t * int_handlers = (OS_ctty_get_int_char_handlers ());
  128.     unsigned char * scan = (STRING_LOC (result, 0));
  129.  
  130.     for (i = 0; i < num_chars; i++)
  131.     {
  132.       (*scan++) = ((unsigned char) int_chars[i]);
  133.       (*scan++) = ((unsigned char) int_handlers[i]);
  134.     }
  135.     PRIMITIVE_RETURN (result);
  136.   }
  137. }
  138.  
  139. DEFINE_PRIMITIVE ("TTY-SET-INTERRUPT-CHARS!", Prim_tty_set_interrupt_chars, 1, 1,
  140.   "Change the current interrupt characters to STRING.\n\
  141. STRING must be in the correct form for this operating system.")
  142. {
  143.   PRIMITIVE_HEADER (1);
  144.   {
  145.     unsigned int i;
  146.     unsigned int num_chars = (OS_ctty_num_int_chars ());
  147.     cc_t * int_chars = (OS_ctty_get_int_chars ());
  148.     cc_t * int_handlers = (OS_ctty_get_int_char_handlers ());
  149.     SCHEME_OBJECT argument = (ARG_REF (1));
  150.     unsigned char * scan;
  151.  
  152.     if (! ((STRING_P (argument))
  153.        && ((STRING_LENGTH (argument)) == (num_chars * 2))))
  154.       error_wrong_type_arg (1);
  155.  
  156.     for (i = 0, scan = (STRING_LOC (argument, 0)); i < num_chars; i++)
  157.     {
  158.       int_chars[i] = (*scan++);
  159.       int_handlers[i] = (*scan++);
  160.     }
  161.     OS_ctty_set_int_chars (int_chars);
  162.     OS_ctty_set_int_char_handlers (int_handlers);
  163.   }
  164.   PRIMITIVE_RETURN (UNSPECIFIC);
  165. }
  166.